package testcase
import (
	httpexpect "github.com/gavv/httpexpect/v2"
	"net/http"
	appmanagertest "saas_sys_base/testcase/appmanager"
	. "saas_sys_base/testcase/testdata"
	//usertest "saas_sys_base/testcase/user"
	tenanttest "saas_sys_base/testcase/tenant"
)

type TestDataForCurEnvStru struct {
    TenantId int64
    MiniAppId int64
}

var TestDataForCurEnv TestDataForCurEnvStru

func SetupEnvironment(t httpexpect.LoggerReporter) *TestDataForCurEnvStru {

	//创建一个租户，并给该租户的对应app赋予权限
	{
		resp, respObj := tenanttest.PostCreateTenantWithMember(t, TestDataForTenant.HeaderMapDefault)
		resp.Status(http.StatusOK). //判断请求是否200
			JSON().
			Object().                  //json body实例化
			ContainsKey("code").       //检验是否包括key
			ValueEqual("code", 0). //对比key的value
		    ValueEqual("msg", "success")


		//t.Logf("respResult:", respResult)

		TestDataForCurEnv.TenantId = respObj.Data.TenantMember.TenantId
		TestDataForCurEnv.MiniAppId = 20000
	}

	{
		var req appmanagertest.AddAppPermissionExpireTimeRequest
		req.AppId = TestDataForCurEnv.MiniAppId
		req.Tid = TestDataForCurEnv.TenantId
		req.Duration = 999999999
		resp := appmanagertest.PostAddAppPermissionExpireTime(t, &req, TestDataForTenant.HeaderMapDefault)
		resp = resp

	}

    return &TestDataForCurEnv
}